package Modelo;

import Controlador.MotorPolicia;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Policia extends Movil implements Serializable {

    private static final long serialVersionUID = 14L;


     

   
   MotorPolicia  motor;


    public Policia(Integer id0, Integer x0,Integer y0,Integer w0,Integer h0,Color c,Integer vida, Boolean estado){

        super(id0,x0,y0,h0,w0,c,vida,estado);

            signo = this.SentidoAleatorio();
         
            dx=3*signo;
            dy=3*signo;

     
    }

    
    public void addMotor(){   
         motor = new MotorPolicia(this);
         motor.start();
    }
    
    
     public void avanzar(){
           

         xAnterior=x;
         yAnterior=y;

         x += -dx;
         y += dy;
       
      try{
        perito.checkCollisions((Policia) this);
      }
      catch (Exception e) {}
     }

    @Override
    public void dibujar(Graphics g) {
        g.setColor(color); 
        g.fillOval(x, y, ancho, alto);
    } 


    @Override
    public synchronized void colision(Pared pared) {
      System.out.println("Soy el poli" + this.id.toString() + " y me choque con " + pared.getID()  );
        
    }

    @Override
    public void colision(Base base) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void colision(Destino destino) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

     @Override
    public synchronized void colision(Policia policia) {
            policia.back();
             
            signo = policia.SentidoAleatorio();
   
            policia.dx = policia.dx*(signo);
            policia.dy = policia.dy*(signo)*(-1);
              
     }
    
    @Override
    public void colision(Figuras figura) {

        System.out.println("Colision con Figura \n");
    }


 @Override
   public void colision(Autito auto) {

       auto.rebota();
       this.back();

       signo = this.SentidoAleatorio();

       this.dx = this.dx*(signo);
       this.dy = this.dy*(signo)*(-1);

       arbitro.CheckAll(auto);
   }

    public  synchronized void detenerse() {
        try {
            this.motor.wait();
        } catch (InterruptedException ex) {
            Logger.getLogger(Policia.class.getName()).log(Level.SEVERE, null, ex);
        }

}

    


       @Override
 public void colision(Semaforo s) {
System.out.println("POLICIAAAAAAAAAAA Y SEMAFOROOOOOOOOOOOOOOO");
 }


    public void keyTyped(KeyEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void keyPressed(KeyEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void keyReleased(KeyEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }


}


